#ifndef DATA_TYPE_H
#define DATA_TYPE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include <cjson/cJSON.h>
#include <pthread.h>
#include "comm.h"
#include <semaphore.h>
#include <pthread.h>
#include <libubus.h>
 
#include <libubox/uloop.h>
#include <libubox/list.h>
#include <libubox/blobmsg_json.h>
#include <json-c/json.h>

#define INFO_LEN 40
//通过MQTT上传数据的设备类型定义

typedef char update_info_t[INFO_LEN];

///MPPT电池信息
typedef struct
{
    char            powerStatus;//电源模块当前状态
    short           offTime;    //电源模块休眠时长，单位m(分钟)
    short           onTime;     //电源模块唤醒时长，单位m(分钟)

    unsigned char  batteryCapacity;//电池剩余百分比,单位无，为整数，0~100

    float           columnVoltage;//阵列电压 V
    float           fArrayCur;//阵列电流 A
    char            columnStatus;//阵列状态

    float           batteryVoltage;//蓄电池电压 V
    float           batteryElectric;//蓄电池电流 A
    char            batteryStatus;//蓄电池状态

    unsigned short  sChargeStatus;//充电设备状态
    unsigned short  sDischargeStatus;//放电设备状态

    float           loadVoltage;//负载电压 V
    float           loadElectric;//负载电流 A
    float           loadPower;//负载功率 W
    char            loadStatus;//负载状态

    unsigned int    runDay;     //控制器运行天数
    unsigned int    lowVolCnt;  //欠压次数
    unsigned int    todayDischarge;   //今日放电量
    unsigned int    yesterdayDischarge;//昨日放电量
    unsigned long   totalDischarge;//总放电量
    unsigned int    todayCharge;//今日充电量
    unsigned int    yesterdayCharge;//昨日充电量
    unsigned long   totalCharge;//总充电量
    
    float           fDevTemperature;//控制器内部温度
    float           fBatTemperature;//电池内部温度，单位摄氏度
}StEnergyInfo;
/**MQTT服务器信息 */
typedef struct
{
    bool  enable;
    char *host;
    int   port;
    char *username;
    char *password;
    char *subtopic;
    char *pubtopic;
} MQTTServer;

typedef struct
{
    char *sn;
    int cmdType;
    int devChannel;
    char *cmdValue;
    char *proxyName;
    char *localIp;
    int localPort;
    int remotePort;
    char *remoteIp;
    int proxyPort;
} CmdInfo;

/**MQTT数据报文 */
typedef struct{
    char *sn;
    char dataType;
    char version;
    void *data;
} MQTT_Data;
//无线网桥配置
typedef struct
{
    char *sn;
    uint16_t lora_addr;
    uint16_t lora_group;
    uint16_t lora_trans;
    uint8_t work_time[9];
    uint8_t sleep_time[9];
    char *device;
    int speed;
    char *iot_enable;
    char *bridge_enable;
    char *lte_enable;
    char *mesh_enable;
} t_RunCfg;
typedef struct
{
    char *ip;
    char *type;
    char *label;
} BridgeCfg;

typedef struct{
    sem_t sem;
    pthread_mutex_t mutex;
    unsigned char data[128];
    unsigned char len;
} pShartData;
/**1、无线网桥数据报文 */
typedef struct{
    char *deviceMode;
    char *wirelessMode;
    char *channelWidth;
    char *antennaGain;
    char *pointDistance;
    char *accessPointsNumber;
    char *encryptionMethod;
    char *portMode;
    char *mtu;
    char *ssid;
    char *model;
    char *ip;
    char *mac;
    char *netmask;
    char *gatewayIp;
    char *preferedDnsIP;
    char *alternateDnsIP;
    char *softwareVersion;
}BridgeBasicData;
typedef struct{
    char *workingFrequency;
    char *transmitPower;
    char *signalStrength;
    char *backgroundNoise;
    char *polarizationSignalDifference;
    char *transmissionCapacity;
    char *receptionThroughput;
    char *delay;
    char *cinrCarrier;
    char *cpu;
    char *sendBytes;
    char *receivedBytes;
    unsigned long runningTime;
    char *deviceCurrentTime;
}BridgeStatusData;
typedef struct{
    char *ip;
    char *mac;
    char *name;
}BridgeRemoteInfo;
typedef struct{
    BridgeBasicData basicData;
    BridgeStatusData statusData;
    BridgeRemoteInfo *remoteInfos;
    char *sn;
} BridgeData;
/**2、边带数据报文 */
typedef struct{
    char *startTime;
    char *sleepTime;
    char *model;
    char *version;
    char *ip;
    char *mac;
    char *gateway;
    char *netmask;
    char *dns;
} IotBasicData;
typedef struct{
    char *cpu;
    char *memory;
    char *portFlow;
    char *currentTime;
    char *longitude;
    char *latitude;
    char *altitude;
} IotStatusData;
typedef struct{
    bool lan1;
    bool lan2;
    bool lan3;
    bool lan4;
    bool wan;
} IotPortInfo;
typedef struct{
    IotBasicData basicData;
    IotStatusData statusData;
    IotPortInfo portInfo;
} IotData;

/**3、电源数据报文 */
typedef struct
{
    char            powerStatus;//电源模块当前状态
    short           offTime;    //电源模块休眠时长，单位m(分钟)
    short           onTime;     //电源模块唤醒时长，单位m(分钟)

    unsigned char  batteryCapacity;//电池剩余百分比,单位无，为整数，0~100

    float           columnVoltage;//阵列电压 V
    float           fArrayCur;//阵列电流 A
    char            columnStatus;//阵列状态

    float           batteryVoltage;//蓄电池电压 V
    float           batteryElectric;//蓄电池电流 A
    char            batteryStatus;//蓄电池状态

    unsigned short  sChargeStatus;//充电设备状态
    unsigned short  sDischargeStatus;//放电设备状态

    float           loadVoltage;//负载电压 V
    float           loadElectric;//负载电流 A
    float           loadPower;//负载功率 W
    char            loadStatus;//负载状态

    unsigned int    runDay;     //控制器运行天数
    unsigned int    lowVolCnt;  //欠压次数
    unsigned int    todayDischarge;   //今日放电量
    unsigned int    yesterdayDischarge;//昨日放电量
    unsigned long   totalDischarge;//总放电量
    unsigned int    todayCharge;//今日充电量
    unsigned int    yesterdayCharge;//昨日充电量
    unsigned long   totalCharge;//总充电量
    
    float           fDevTemperature;//控制器内部温度
    float           fBatTemperature;//电池内部温度，单位摄氏度
}EnergyInfo;
typedef struct{
    short addr;
    short gateway;
    char status;
    short offTime;
    short onTime;
} EnergyStatus;
typedef struct{
    EnergyInfo powerData;
    EnergyStatus statusData;
} EnergyData;
/**4、4G/5G数据报文 */

/**5、Mesh自组网数据报文 */
#endif //DATA_TYPE_H
